<?php

/**
 * Ngo Framework -  Zend Framework Tunning
 *
 * @author ngo
 */
abstract class Ngo_Db_Table_Abstract extends Zend_Db_Table_Abstract {

    public function __construct($config = array()) {
        if (empty($config)) {
            $connexion = new Zend_Config_Ini(APPLICATION_PATH . '/configs/database.ini', APPLICATION_ENV);
            $config = Zend_Db::factory($connexion->database);
        }

        parent::__construct($config);
    }

    /**
     * auto setup for the table name from the class name 
     */
    protected function _setupTableName() {
        if (!$this->_name) {
            $this->_name = $this->_generateTableName(get_class($this));
        }
        parent::_setupTableName();
    }

    /**
     * Parse Table Name from class Name
     * @param string $class_name classe name
     * @return string Table name
     */
    protected function _generateTableName($class_name) {
        return strtolower(preg_replace('/^Db_Table_/', '', $class_name));
    }

}